local desc_vanished_dragon = [[
  # 忠胆英杰（明忠模式）简介

  ---
  ## 计算体力上限

  亮出身份牌的忠臣增加1点体力上限。
  
  # 游戏流程

  1. **明忠如一般身份局的主公一样，先选将并展示**，其他人（包括主公）再选将。明忠的固定额外选将为 崔琰 和 皇甫嵩(若在房间禁表则不会出现)；

  2. 明忠根据体力上限(不计明忠血量上限加成)和性别获得相应的“**忠臣技**”，即：

  - 体力上限不大于3的男性武将获得〖**洞察**〗（游戏开始时，随机一名反贼的身份对你可见。准备阶段开始时，你可以弃置场上的一张牌）；

  - 体力上限不小于4的男性武将和所有女性武将获得〖**舍身**〗（锁定技，主公处于濒死状态即将死亡时，你令其体力上限+1，回复体力至X点（X为你的体力值），获得你所有牌，然后你死亡）；

  3. 如一般身份局的主公一样，**明忠体力上限和体力值+1**，且为一号位；

  4. **明忠死亡后，主公亮明身份**，获得武将牌上的主公技，但不增加体力上限。

  ---

  ## 击杀奖惩

  1. 任何角色击杀反贼，摸三张牌；

  2. 除主公外的角色击杀明忠，摸三张牌；

  3. 暗主击杀明忠，弃置所有牌；

  4. 暗主击杀暗忠，不弃牌；

  5. 明忠击杀暗忠，弃置所有牌。

  ## 角色死亡

  角色濒死和死亡的结算与身份局相同。奖惩的执行如下：1.任何角色杀死一名反贼，立刻摸三张牌；2.主公杀死忠臣，若主公的身份牌已经亮出，主公须弃置所有牌。若主公的身份牌没有亮出则没有事情发生。3.亮出身份牌的忠臣死亡后，抽到主公身份的玩家须亮出身份牌并获得主公技（若有）。
  
  ## 游戏结束（与身份局相同）
  
  当以下任意一种情况发生时，游戏立即结束：1.主公被杀，此时若内奸是唯一存活的角色（有且仅有一名内奸存活），则内奸获胜，除此之外的情况为反贼获胜（不论反贼角色死活）。2. 所有的反贼和内奸都已死亡：主公和忠臣（不论死活）都获胜。

  ## 规则魔改(未生效)：
   1.一名角色一回合摸牌数不得超过50。

  2.一名角色一回合累计发动同一技能超过50次则失效。

  3.大于等于7号位的角色获得1点护甲。
]]


local vanished_dragon_getLogic = function()
  local vanished_dragon_logic = GameLogic:subclass("vanished_dragon_logic")

  function vanished_dragon_logic:initialize(room)
    GameLogic.initialize(self, room)
    self.role_table = {nil, nil, nil, nil, nil,
    {"lord", "loyalist", "rebel", "rebel", "rebel", "renegade"},
    {"lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "renegade"}, 
    {"lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "rebel", "renegade"},
    {"lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "rebel", "renegade", "renegade"},
    {"lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "rebel", "renegade", "renegade", "loyalist"}}
  end

  function vanished_dragon_logic:assignRoles()
    local room = self.room---@type Room
    local players = room.players
    local n = #players
    local roles = self.role_table[n]
    table.shuffle(roles)

    room:setBanner("ShownLoyalist", nil)
    for i = 1, n do
      local p = players[i]
      p.role = roles[i]
      room:broadcastProperty(p, "role")
      if p.role == "loyalist" and not room:getBanner("ShownLoyalist") then
        room:setPlayerProperty(p, "role_shown", true)
        room:setBanner("ShownLoyalist", p.id)
      end
    end
  end

  function vanished_dragon_logic:adjustSeats()
    local player_circle = {}
    local players = self.room.players
    local p = 1

    for i = 1, #players do
      if players[i].id == self.room:getBanner("ShownLoyalist") then
        p = i
        break
      end
    end
    for j = p, #players do
      table.insert(player_circle, players[j])
    end
    for j = 1, p - 1 do
      table.insert(player_circle, players[j])
    end

    self.room:arrangeSeats(player_circle)
  end

  function vanished_dragon_logic:chooseGenerals()
    local room = self.room---@type Room

    local generals_blacklist = {
      -- 暴露暗主
      "js__caocao", "js__zhugeliang", "ol__dongzhao", "std__yuanshu", "huanghao", "mou__guanyu", "godlusu",
      "mobile__yuanshu", "m_ex__yuanshu", "guandu__xuyou",
    }
    local loyalist_list = {}
    for i = #room.general_pile, 1, -1 do
      local name = room.general_pile[i]
      if table.contains(generals_blacklist, name) then
        if name == "mod__cuiyan" or name == "zyg_ex_zy__pangde" then
          table.insert(loyalist_list, name)
        end
        table.remove(room.general_pile, i)
      end
    end

    local generalNum = room.settings.generalNum
    local n = room.settings.enableDeputy and 2 or 1
    local lord = room.players[1] -- room:getLord()
    if lord.id == room:getBanner("ShownLoyalist") then
      for _, p in ipairs(room.players) do
        if p.id == room:getBanner("ShownLoyalist") then
          lord = p
          break
        end
      end
    end

    room:sendLog{
      type = "#VDIntro",
      arg = lord._splayer:getScreenName(),
      toast = true,
    }

    if lord ~= nil then
      room:setCurrent(lord)
      table.insertTable(loyalist_list, table.random(room.general_pile, generalNum))
      local lord_generals = room:askToChooseGeneral(lord, {
        generals = loyalist_list,
        n = n,
      })
      local lord_general, deputy
      if type(lord_generals) == "table" then
        deputy = lord_generals[2]
        lord_general = lord_generals[1]
      else
        lord_general = lord_generals
        lord_generals = {lord_general}
      end
      for _, g in ipairs(lord_generals) do
        room:findGeneral(g)
      end

      room:prepareGeneral(lord, lord_general, deputy, true)
      room:askToChooseKingdom({lord})

      -- 显示技能
      local canAttachSkill = function(player, skillName)
        local skill = Fk.skills[skillName]
        if not skill then
          fk.qCritical("Skill: "..skillName.." doesn't exist!")
          return false
        end
        if skill:hasTag(Skill.AttachedKingdom) and not table.contains(skill:getSkeleton().attached_kingdom, player.kingdom) then
          return false
        end
        return true
      end

      local lord_skills = {}
      local lord_gs = Fk.generals[lord_general]
      for _, s in ipairs(lord_gs:getSkillNameList()) do
        if canAttachSkill(lord, s) then
          table.insertIfNeed(lord_skills, s)
        end
      end
      local deputyGeneral = Fk.generals[lord.deputyGeneral]
      if deputyGeneral then
        for _, s in ipairs(deputyGeneral:getSkillNameList()) do
          if canAttachSkill(lord, s) then
            table.insertIfNeed(lord_skills, s)
          end
        end
      end
      local lord_maxhp = deputyGeneral and (lord_gs.maxHp + deputyGeneral.maxHp) // 2 or lord_gs.maxHp
      table.insert(lord_skills, (lord_maxhp <= 3 and lord_gs.gender == General.Male) and "vd_dongcha&" or "vd_sheshen&")
      for _, skill in ipairs(lord_skills) do
        room:doBroadcastNotify("AddSkill", json.encode{ lord.id, skill })
      end
    end

    local nonlord = room:getOtherPlayers(lord, true)
    local generals = table.random(room.general_pile, #nonlord * generalNum)

    local req = Request:new(nonlord, "AskForGeneral")
    for i, p in ipairs(nonlord) do
      local arg = table.slice(generals, (i - 1) * generalNum + 1, i * generalNum + 1)
      req:setData(p, { arg, n })
      req:setDefaultReply(p, table.random(arg, n))
    end

    for _, p in ipairs(nonlord) do
      local result = req:getResult(p)
      local general, deputy = result[1], result[2]
      room:findGeneral(general)
      room:findGeneral(deputy)
      room:prepareGeneral(p, general, deputy)
    end

    room:askToChooseKingdom(nonlord)
  end


  function vanished_dragon_logic:attachSkillToPlayers()
    local room = self.room
    local players = room.players
    local lord = room:getBanner("ShownLoyalist")

    local addRoleModSkills = function(player, skillName)
      local skill = Fk.skills[skillName]
      if skill:hasTag(Skill.Lord) then
        return
      end

      if skill:hasTag(Skill.AttachedKingdom) and not table.contains(skill:getSkeleton().attached_kingdom, player.kingdom) then
        return
      end

      room:handleAddLoseSkills(player, skillName, nil, false)
    end
    for _, p in ipairs(room.alive_players) do
      local skills = Fk.generals[p.general].skills
      for _, s in ipairs(skills) do
        addRoleModSkills(p, s.name)
      end
      for _, sname in ipairs(Fk.generals[p.general].other_skills) do
        addRoleModSkills(p, sname)
      end

      local deputy = Fk.generals[p.deputyGeneral]
      if deputy then
        skills = deputy.skills
        for _, s in ipairs(skills) do
          addRoleModSkills(p, s.name)
        end
        for _, sname in ipairs(deputy.other_skills) do
          addRoleModSkills(p, sname)
        end
      end

      if p.id == lord then
        local skill = (p.maxHp <= 4 and p:isMale()) and "vd_dongcha&" or "vd_sheshen&"
        room:sendLog{
          type = "#VDLoyalistSkill",
          from = p.id,
          arg = skill,
          toast = true,
        }
        room:handleAddLoseSkills(p, skill, nil, false)
      end
    end
  end

  return vanished_dragon_logic
end

local vanished_dragon = fk.CreateGameMode{
  name = "zyg_vanished_dragon",
  minPlayer = 6,
  maxPlayer = 10,
  main_mode = "role_mode",
  rule = "#vanished_dragon_rule&",
  logic = vanished_dragon_getLogic,
  surrender_func = function(self, playedTime)
    return Fk.game_modes["aaa_role_mode"].surrenderFunc(self, playedTime)
  end,
  get_adjusted = function (self, player)
    if player.room:getBanner("ShownLoyalist") == player.id then
      return {hp = player.hp + 1, maxHp = player.maxHp + 1}
    end
    return {}
  end,
  reward_punish = function (self, victim, killer)
    if not killer or killer.dead then return end
    local shownLoyalist = victim.room:getBanner("ShownLoyalist")
    if victim.role == "loyalist" and ((killer.role == "lord" and killer.role_shown) or killer.id == shownLoyalist) then
      killer:throwAllCards("he")
    elseif victim.role == "rebel" or victim.id == shownLoyalist then
      killer:drawCards(3, "kill")
    end
  end,
  build_draw_pile = function(self)
    local draw, void = GameMode.buildDrawPile(self)
    local blacklist = {
    }
    local whitelist = {
    }

    for i = #void, 1, -1 do
      local id = void[i]
      local card = Fk:getCardById(id)
      local name = card.name
      if table.contains(whitelist, name) then
        table.remove(void, i)
        table.insert(draw, id)
      end
    end

    for i = #draw, 1, -1 do
      local id = draw[i]
      local card = Fk:getCardById(id)
      local name = card.name
      if table.contains(blacklist, name) then
        table.remove(draw, i)
        table.insert(void, id)
      end
    end

    return draw, void
  end
}

Fk:loadTranslationTable{
  ["zyg_vanished_dragon"] = "忠胆英杰(空牌堆)",
  [":zyg_vanished_dragon"] = desc_vanished_dragon,

}

return vanished_dragon
